﻿<template>
  <a-card :bordered="false">
    <div class="table-operator" style="display: flex; justify-content: space-between">
      <div>
        <a-button type="primary" @click="SearchClick()">申请开票</a-button>
      </div>
      <a-form layout="inline">
        <a-row>
          <a-col :md="24" :sm="24">
            <!-- <a-input
              style="width: 150px"
              v-model="queryParam.keyword"
              placeholder="请输入购货方名称"
              @keydown.enter="
                () => {
                  this.pagination.current = 1
                  this.getDataList()
                }
              "
            /> -->
            <searchTip
              v-model="queryParam.RealName"
              style="width: 150px;margin-left:10px; display: inline-block"
              tipStyle="width:150px;left:0;"
              placeholder="申请人"
              :list="searchTipNameList"
              @enterKeyDown="getDataList"
              @change="toGetSearchTipNameList"
              @blur="nameBlurFun"
              @select="selectNameSearchTipFun"
            />
            <searchTip
              v-model="queryParam.keyword"
              style="width: 150px;margin-left:10px; display: inline-block"
              placeholder="请输入购货方名称"
              tipStyle="width:300px;left:0;"
              :list="searchTipResultList"
              @enterKeyDown="getDataList"
              @change="toGetSearchTipList"
              @blur="keywordBlurFun"
              @select="selectSearchTipFun"
            />

            <a-select
              allowClear
              v-model="queryParam.IsInvoice"
              placeholder="开票状态"
              style="width: 120px; margin-left: 10px"
            >
              <a-select-option v-for="i in invoiceStateSelectOptions" :key="i.value" :value="i.value">
                {{ i.label }}
              </a-select-option>
            </a-select>
            <a-select
              allowClear
              v-model="queryParam.RefundStatus"
              placeholder="退票状态"
              style="width: 120px; margin-left: 10px"
            >
              <a-select-option v-for="i in RefundStatusSelectOptions" :key="i.value" :value="i.value">
                {{ i.label }}
              </a-select-option>
            </a-select>
            <a-select
              allowClear
              v-model="queryParam.IsApply"
              placeholder="状态"
              style="width: 120px; margin-left: 10px"
            >
              <a-select-option v-for="i in typeSelectOptions" :key="i.value" :value="i.value">
                {{ i.label }}
              </a-select-option>
            </a-select>
            <a-select
              style="width: 100px; margin-left: 8px"
              v-model="selectTime"
              @change="changeTime"
              name="radioGroup"
              :default-value="0"
            >
              <a-select-option :value="index" v-for="(i, index) in ['一个月', '三个月', '六个月', '自定义']" :key="i">
                {{ i }}
              </a-select-option>
            </a-select>

            <a-range-picker
              style="margin-left: 8px; width: 220px"
              :disabled="timeDisabled"
              valueFormat="YYYY-MM-DD"
              v-model="time"
            />
            <a-button
              style="margin-left: 8px"
              type="primary"
              @click="
                () => {
                  this.pagination.current = 1
                  this.getDataList()
                }
              "
              >查询
            </a-button>
            <a-button @click="repossess">重置 </a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="table-page-search-wrapper"></div>

    <div style="position:relative;">
      <a-table
        ref="table"
        style="width: 100%"
        :scroll="{ y: 'calc(100vh - 320px)', x: 1420 }"
        :columns="columns"
        :rowKey="(row) => row.Id"
        :dataSource="data"
        :pagination="pagination"
        :loading="loading"
        @change="handleTableChange"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :bordered="true"
        size="small"
      >
        <!-- :rowClassName="(record, index) => (record.RefundStatus ? 'active' : null)" -->
        <template slot="Amountincludingtax" slot-scope="text, record">
          {{ record.Amountincludingtax }}
        </template>
        <span slot="ApplicantTime" slot-scope="ApplicantTime">{{ timeFormat(ApplicantTime, 'YYYY-MM-DD') }}</span>
        <span slot="IsInvoice" slot-scope="text, record"
          ><a-tag :color="record.IsInvoice ? 'blue' : 'purple'">{{ record.IsInvoice ? '是' : '否' }}</a-tag></span
        >
        <span slot="RefundStatus" slot-scope="text, record"
          ><a-tag :color="record.InvoiceState == 20 || record.InvoiceState == 30 ? 'blue' : 'purple'">{{
            record.InvoiceState == 20 || record.InvoiceState == 30 ? '是' : '否'
          }}</a-tag></span
        >
        <span slot="Remark" slot-scope="text, record"
          >{{ record.Remark ? record.Remark.replace(/null/g,'') :'' }}
        </span>
        <template slot="IsApply" slot-scope="text, record">
          <a-tag v-if="text == 1" color="#87d068">审批通过</a-tag>
          <a-tag v-else-if="text == 2" color="red">审批驳回</a-tag>
          <a-tag v-else-if="text == 0 || text == ''" color="#2db7f5">待审批</a-tag>
          <a-tag v-else-if="text == 3" color="red">已作废</a-tag>
        </template>
        <!-- <template slot="State" slot-scope="text, record">
        <a-tag
          :color="record.State === 'Running'
            ? 'green'
            : record.State === 'Finished'
              ? 'blue'
              : record.State === 'Canceled'
                ? 'orange'
                : record.State === 'Exceptional'
                  ? 'red'
                  : record.State === 'Suspended'
                    ? 'pink'
                    : record.State === 'Timeout'
                      ? 'purple'
                      : 'green'">{{ record.State === 'Running'
          ? '审批中'
          : record.State === 'Finished'
            ? '已完成'
            : record.State === 'Canceled'
              ? '已驳回'
              : record.State === 'Exceptional'
                ? '异常'
                : record.State === 'Suspended'
                  ? '已停止'
                  : record.State === 'Timeout'
                    ? '已超时'
                    : '审批中' }}</a-tag>

      </template> -->
        <span slot="action" slot-scope="text, record">
          <template>
            <!-- <a v-if="hasPerm('Base_District.Edit')" @click="handleEdit(record.Id)">编辑</a> -->
            <a
              v-if="record.IsApply !== 1 && hasPerm('Base_District.redact') && record.IsApply !== 3"
              @click="handleEdit(record)"
              style="margin-right: 10px"
              >编辑</a
            >
            <!-- <a-divider v-if="hasPerm('Base_District.Edit') && hasPerm('Base_District.Delete')" type="vertical" /> -->
            <a v-if="hasPerm('Base_District.view')" @click="handleview(record)">详情</a>
            <a
              v-if="!record.IsInvoice && record.IsApply == 1"
              style="margin-left: 10px"
              @click="handleNoExamine(record)"
              >取消审核</a
            >

            <a
              v-if="hasPerm('Base_District.apply') && record.IsApply !== 1 && record.IsApply !== 3"
              @click="handleApply(record)"
              style="margin-left: 10px"
              >通过</a
            >
            <a
              v-if="hasPerm('Base_District.Reject') && record.IsApply === 0 && record.IsApply !== 3"
              @click="handleReject(record)"
              style="margin-left: 10px; color: red"
              >驳回</a
            >
            <a
              v-if="hasPerm('Base_District.Deleted') && !record.IsInvoice && record.IsApply != 3"
              @click="handleCancel(record)"
              style="margin-left: 10px; color: red"
              >作废</a
            >
            <a
              v-if="hasPerm('Base_District.Detail') && record.IsInvoice"
              @click="handleDetail(record)"
              style="margin-left: 10px"
              >发票详情</a
            >
            <a @click="handleCorrelation(record)" style="margin-left: 10px">关联货单</a>
            <a
              v-if="record.InvoiceState == 20 || record.InvoiceState == 30"
              @click="handleCopy(record)"
              style="margin-left: 10px"
              >复制</a
            >
            <!-- <a-divider v-if="hasPerm('Base_District.Edit') && hasPerm('Base_District.Delete')" type="vertical" />
          <a v-if="record.InstanceId" @click="handleHistory(record.NewInstanceId)">审批历史</a>
          <a-divider v-if="record.State == 'Finished' && record.Isreturnticket" type="vertical" /> -->
            <!-- <a v-if="record.State == 'Finished' && record.Isreturnticket" @click="returnTicket(record)">退票</a> -->
          </template>
        </span>
      </a-table>
      <div style="position:absolute;bottom:5px;">
        <p>金额合计:{{ PriceCount }}</p>
      </div>
    </div>

    <SearchCusinfo ref="SearchCusinfo" :parentObj="{ ...this }"></SearchCusinfo>
    <OutboundDetails ref="OutboundDetails" :parentObj="{ ...this }" />
    <OutboundDetailsCopy ref="OutboundDetailsCopy" :parentObj="{ ...this }" />
    <EditForm ref="EditForm" :parentObj="{ ...this }" />
    <printCopy ref="printCopy1" />
    <a-drawer
      title="选择"
      placement="right"
      width="30%"
      :closable="false"
      :maskClosable="false"
      :visible="SelectIdVisible"
      @close="
        () => {
          this.SelectIdVisible = false
          this.SelectIdList = []
        }
      "
    >
      <printCopy ref="printCopy2" />
      <div style="margin-bottom: 50px">
        <a-table
          :row-selection="SelectIdRow"
          :rowKey="(row) => row.Id"
          :columns="columnsId"
          :pagination="false"
          :data-source="dataId"
        >
        </a-table>
      </div>

      <div
        :style="{
          position: 'absolute',
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e8e8e8',
          padding: '10px 16px',
          textAlign: 'right',
          left: 0,
          background: '#fff',
          borderRadius: '0 0 4px 4px',
        }"
      >
        <a-button
          style="margin-right: 8px"
          @click="
            () => {
              this.SelectIdVisible = false
              this.SelectIdList = []
            }
          "
        >
          取消
        </a-button>
        <a-button type="primary" @click="selectIdOk"> 确定 </a-button>
      </div>
    </a-drawer>
    <a-drawer
      title="发票详情"
      :visible="visibleDetail"
      width="80%"
      @close="
        () => {
          this.visibleDetail = false
          this.invoiceDetail = []
        }
      "
    >
      <a-table
        ref="table"
        :scroll="{ y: 530 }"
        :columns="columnsDetail"
        :rowKey="(row, index) => row.Id"
        :dataSource="invoiceDetail"
        :pagination="false"
        :bordered="true"
        size="small"
      >
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="handleDetail_Detail(record.Id)">详情</a>
          </template>
        </span>
      </a-table>
    </a-drawer>
    <a-drawer
      title="详情信息"
      :visible="visibleDetail_Detail"
      width="80%"
      @close="
        () => {
          this.visibleDetail_Detail = false
          this.invoiceDetail_detail = []
        }
      "
    >
      <a-descriptions>
        <a-descriptions-item label="订单号码">{{ invoiceDetail_entity.Code }}</a-descriptions-item>
        <a-descriptions-item label="开票人">{{ invoiceDetail_entity.createUserName }}</a-descriptions-item>
        <a-descriptions-item label="开票日期">{{ invoiceDetail_entity.CreateTime }}</a-descriptions-item>
      </a-descriptions>
      <a-table
        ref="table"
        :scroll="{ y: 530 }"
        :columns="columnsDetail_detail"
        :rowKey="(row, index) => row.Id"
        :dataSource="invoiceDetail_detail"
        :pagination="false"
        :bordered="true"
        size="small"
      >
        <span slot="Index" slot-scope="text, record, i">
          <template>
            {{ i + 1 }}
          </template>
        </span>
      </a-table>
    </a-drawer>
    <a-drawer
      title="审批历史"
      width="30%"
      :confirmLoading="loading"
      placement="right"
      :visible="visible"
      @close="
        () => {
          this.visible = false
        }
      "
      :body-style="{ paddingBottom: '80px' }"
    >
      <a-steps progress-dot :current="steps.length - 1" direction="vertical">
        <a-step v-for="(item, index) in steps" :key="index" :title="item.Title">
          <div style="width: 300px" slot="description">
            <div>
              <span>{{ item.UserName }}</span>
              <a-tag :color="item.color"> {{ item.type }} {{ item.State == 'Finished' ? item.FinishTime : '' }} </a-tag>
            </div>
            <span v-show="item.State != 'ToDo' && item.Comment">{{ item.Comment }}</span>
            <p>{{ item.StartTime }}</p>
          </div>
        </a-step>
      </a-steps>
    </a-drawer>
  </a-card>
</template>

<script>
import moment from 'moment'
import SearchCusinfo from './SearchCusinfo'
import OutboundDetails from './OutboundDetails.vue'
import OutboundDetailsCopy from './OutboundDetailsCopy.vue'
import EditForm from './EditForm.vue'
import printCopy from '../ReceiptSign/waybill/printCopyAssociation.vue'
import searchTip from '@/components/components/SearchTip.vue'

const columnsDetail = [
  { title: '购货方', dataIndex: 'CusName', width: '350px' },
  { title: '发票代码', dataIndex: 'Invoicecode', align: 'center' },
  { title: '发票号码', dataIndex: 'Invoicenumber', align: 'center' },
  { title: '开票金额', dataIndex: 'InvoiceAmount', align: 'right', width: '150px' },
  { title: '税额', dataIndex: 'InvoiceTaxAmount', align: 'right', width: '150px' },
  { title: '开票日期', dataIndex: 'CreateTime', align: 'right', width: '150px' },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'center',
    fixed: 'right',
    width: '60px',
    scopedSlots: { customRender: 'action' },
  },
]
const columnsDetail_detail = [
  { title: '序号', dataIndex: 'Index', scopedSlots: { customRender: 'Index' }, width: '60px', align: 'center' },
  { title: '商品名称', dataIndex: 'goodsName' },
  { title: '税收分类编码', dataIndex: 'revenueCode', width: '200px', align: 'center' },
  { title: '数量', dataIndex: 'quantity', align: 'right' },
  { title: '单位', dataIndex: 'unit', align: 'right', width: '60px', align: 'center' },
  { title: '规格', dataIndex: 'specification' },
  { title: '税率', dataIndex: 'taxRate', align: 'right', width: '80px' },
  { title: '含税金额', dataIndex: 'amountWithTax', align: 'right' },
  { title: '税额', dataIndex: 'taxAmount', align: 'right' },
]
const columns = [
{
    title: '申请码',
    dataIndex: 'Code',
    width: '110px'
  },
  {
    title: '申请时间',
    dataIndex: 'ApplicantTime',
    width: '100px',
    scopedSlots: { customRender: 'ApplicantTime' },
  },
  { title: '购货方', dataIndex: 'TicketbuyerName', width: '200px' },
  {
    title: '含税金额(小写)',
    dataIndex: 'Amountincludingtax',
    align: 'right',
    scopedSlots: { customRender: 'Amountincludingtax' },
    width: '150px',
  },
  { title: '地址/电话', dataIndex: 'CusAddress', width: '250px' },
  // { title: '地址', dataIndex: 'PayeeUserAddres', width: '200px' },
  { title: '申请人', dataIndex: 'ApplicantName', width: '100px' },
  { title: '备注', dataIndex: 'Remark', width: '200px', scopedSlots: { customRender: 'Remark' } },
  {
    title: '已开票',
    dataIndex: 'IsInvoice',
    scopedSlots: { customRender: 'IsInvoice' },
    width: '70px',
  },
  { title: '已退票', dataIndex: 'RefundStatus', scopedSlots: { customRender: 'RefundStatus' }, width: '70px' },
  {
    title: '状态',
    dataIndex: 'IsApply',
    scopedSlots: { customRender: 'IsApply' },
    width: '80px',
    // fixed: 'right'
  },
  {
    title: '操作',
    dataIndex: 'action',
    align: 'left',
    width: '200px',
    scopedSlots: { customRender: 'action' },
  },
]
const columnsId = [{ title: '单号', dataIndex: 'BillId' }]
export default {
  components: {
    SearchCusinfo,
    OutboundDetails,
    OutboundDetailsCopy,
    EditForm,
    printCopy,
    searchTip,
  },
  
  data() {
    return {
      tableHeight: 570, // 表格高度
      data: [],
      SelectIdVisible: false,
      SelectIdList: [],
      invoiceDetail_detail: [],
      invoiceDetail_entity: {},
      columnsDetail_detail,
      visibleDetail_Detail: false,
      columnsDetail,
      visible: false,
      visibleDetail: false,
      selectTime: 0,
      correlationId: '',
      invoiceDetail: [],
      pagination: {
        current: 1,
        pageSize: 20,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true,
      },
      filters: {},
      sorter: { field: 'ApplicantTime', order: 'desc' },
      loading: false,
      columns,
      columnsId,
      PriceCount: 0,
      dataId: [],
      queryParam: {
        condition: 'TicketbuyerName',
      },
      selectedRowKeys: [],
      steps: [],
      time: [],
      RefundStatus: 'a',
      timeDisabled: true,
      invoiceStateSelectOptions: [
        {
          value: '1',
          label: '已开票',
        },
        {
          value: '0',
          label: '未开票',
        },
      ],
      RefundStatusSelectOptions: [
        {
          value: '1',
          label: '已退票',
        },
        {
          value: '0',
          label: '未退票',
        },
      ],
      typeSelectOptions: [
        {
          value: 1,
          label: '审批通过',
        },
        {
          value: 2,
          label: '审批驳回',
        },
        {
          value: 0,
          label: '待审批',
        },
        {
          value: 3,
          label: '已作废',
        },
      ],
      searchTipResultList: [],
      searchTipNameList: [],
    }
  },
  mounted() {
    this.$nextTick(() => {
      // 页面渲染完成后的回调
      this.handleResize()
      this.time = [
        this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth(), 1)),
        this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0)),
      ]
      this.getDataList()
    })
  },
  created() {
    window.addEventListener('resize', this.handleResize);
  },
  destroyed() {
    window.removeEventListener('resize', this.handleResize);
  },
  methods: {
    handleResize() {
      try {
        // 页面渲染完成后的回调
        this.tableHeight = this.getTableHeight(true) + 24
      } catch (error) {
        
      }
    },
    handleApply(row) {
      this.$confirm('确认审批通过吗?', '审批', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$http.post(`/InvoiceManagement/Inv_InvoiceApplyMain/SetApplyStatus?id=${row.Id}&state=1`).then((res) => {
          if (res.Success) {
            this.$message.success('审批成功')
            this.getDataList()
          } else {
            this.$message.success(res.Msg)
          }
        })
      })
    },
    handleCancel(row) {
      this.$confirm('确认作废此申请吗?', '审批', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$http.post(`/InvoiceManagement/Inv_InvoiceApplyMain/SetApplyStatus?id=${row.Id}&state=3`).then((res) => {
          if (res.Success) {
            this.$message.success('操作成功')
            this.getDataList()
          } else {
            this.$message.success(res.Msg)
          }
        })
      })
    },
    //发票详情
    handleDetail(record) {
      this.visibleDetail = true
      this.$http
        .post('/InvoiceManagement/Inv_Invoicing/GetDataListByMoreCondition', {
          Search: [{ condition: 'ApplyId', Keyword: record.Id }],
        })
        .then((resJson) => {
          resJson.Data.forEach((item) => {
            item.CreateTime = item.CreateTime.slice(0, 10)
            item.InvoiceAmount = this.$options.filters.NumberFormats(item.InvoiceAmount)
            item.InvoiceTaxAmount = this.$options.filters.NumberFormats(item.InvoiceTaxAmount)
          })
          this.invoiceDetail = resJson.Data
        })
        .catch((err) => {
          this.$message.error(err)
        })
    },
    handleReject(row) {
      this.$confirm('确认审批驳回吗?', '审批', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$http.post(`/InvoiceManagement/Inv_InvoiceApplyMain/SetApplyStatus?id=${row.Id}&state=2`).then((res) => {
          if (res.Success) {
            this.$message.success('审批成功')
            this.getDataList()
          } else {
            this.$message.success(res.Msg)
          }
        })
      })
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.getDataList()
    },
    getDataList() {
      this.searchTipResultList = [] //清空搜索提示列表
      this.searchTipNameList = [] // 清空搜索提示列表
      this.selectedRowKeys = []

      this.loading = true
      const obj = {
        a: '',
        b: false,
        c: true,
      }
      this.$http
        .post('/InvoiceManagement/Inv_InvoiceApplyMain/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: {
            ...this.queryParam,
            IsInvoice: this.queryParam.IsInvoice ? (this.queryParam.IsInvoice == 1 ? true : false) : '',
            // RefundStatus: obj[this.RefundStatus],
            StartTime: this.time[0] ? this.timeFormat(this.time[0]) : '',
            EndTime: this.time[1] ? this.timeFormat(this.time[1]) : '',
          },
          ...this.filters,
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data
          this.data.forEach((item) => {
            item.Amountincludingtax = this.$options.filters.NumberFormats(item.Amountincludingtax)
            item.PayeeUserPhone = `${item.PayeeUserPhone || ''}${item.PayeeUserAddres || ''}`
          })
          this.PriceCount = this.$options.filters.NumberFormats(resJson.TotalMoney)
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
      // this.$http
      //   .post('InvoiceManagement/Inv_InvoiceApplyMain/GetDataAmount', {
      //     PageIndex: this.pagination.current,
      //     PageRows: this.pagination.pageSize,
      //     SortField: this.sorter.field || 'Id',
      //     SortType: this.sorter.order,
      //     Search: {
      //       ...this.queryParam,
      //       // RefundStatus: obj[this.RefundStatus],
      //       StartTime: this.time[0] ? this.timeFormat(this.time[0]) : '',
      //       EndTime: this.time[1] ? this.timeFormat(this.time[1]) : ''
      //     },
      //     ...this.filters
      //   })
      //   .then((resJson) => {
      //     this.PriceCount = resJson.Data;
      //   })
    },
    handleEdit(record) {
      this.$refs.EditForm.openInfo(record, '编辑') // 打开
    },
    handleNoExamine(record) {
      this.$confirm('确认取消审核吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.$http.post('/InvoiceManagement/Inv_InvoiceApplyMain/SetInvoiceApply', { id: record.Id }).then((res) => {
          this.$message.success('操作成功!')
          this.getDataList()
        })
      })
    },
    handleview(record) {
      this.$refs.OutboundDetails.openInfo(record, '详情') // 打开

      // this.$http.post('/InvoiceManagement/Inv_InvoiceApplyMain/GetInvoicingInformation?id' + '=' + record.Id).then(res => {
      //   // this_.$refs.OutboundDetails.handleview(res.Data);
      //   this_.$refs.OutboundDetails.openForm(res.Data.CusCode, record.TicketbuyerName, '详情', record, res.Data)// 打开详情页
      // })  IO-2023-12-0002
    },
    // 复制
    handleCopy(record) {
      this.$http.post('/InvoiceManagement/Inv_InvoiceApplyMain/CheckCopy', { id: record.Id }).then((res) => {
        if(res && res.Success){
          if (res.Data.State) return this.$refs.OutboundDetailsCopy.openInfo(record, '复制') // 打开
          this.$message.error('货品已全部开票完成，不能复制')
        }else{
          this.$message.error(res.Msg)
        }
      })
    },
    //关联货单
    handleCorrelation(record) {
      this.correlationId = record.Id
      this.SelectIdList = []
      this.dataId = []
      this.$http.post('/InvoiceManagement/Inv_InvoiceApplyMain/GetDeliveryDataList', { id: record.Id }).then((res) => {
        if (res.Data.length > 1) {
          this.SelectIdVisible = true
          this.dataId = res.Data
        } else if (res.Data.length == 1) {
          this.$refs.printCopy1.openInit(res.Data[0].Id, res.Data[0].BillId, this.correlationId)
        } else {
          this.$message.error('暂无数据')
        }
      })
      // this.$refs.printCopy.openInit(record.Id)
    },
    changeTime(e) {
      this.timeDisabled = true
      this.selectTime = e
      this.time = []
      switch (e) {
        case 0:
          this.time[0] = this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth(), 1))
          this.time[1] = this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0))
          break
        case 1:
          this.time[0] = this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth() - 2, 1))
          this.time[1] = this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0))
          break
        case 2:
          this.time[0] = this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth() - 5, 1))
          this.time[1] = this.timeFormat(new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0))
          break
        case 3:
          this.timeDisabled = false
          break
      }
    },
    // 状态修改
    selectRefundStatus() {
      this.getDataList()
    },
    // 审批历史
    handleHistory(id) {
      this.visible = true
      const obj = {
        Finished: {
          name: '已完成',
          color: '#87d068',
        },
        ToDo: {
          name: '待办',
          color: 'purple',
        },
        Waiting: {
          name: '等待',
          color: 'red',
        },
        UnRead: {
          name: '未读',
          color: 'red',
        },
        Canceled: {
          name: '驳回',
          color: 'red',
        },
        Draft: {
          name: '草稿',
          color: 'red',
        },
        Timeout: {
          name: '超时',
          color: 'red',
        },
        Skiped: {
          name: '已跳过',
          color: 'red',
        },
      }
      this.$http.post('/InvoiceManagement/Inv_InvoiceApplyMain/Open?InstanceId' + '=' + id).then((res) => {
        res.Data.forEach((item) => {
          item.StartTime = item.StartTime.slice(0, -4)
          item.FinishTime = item.FinishTime.slice(0, -4)
          item.type = obj[item.State].name
          item.color = obj[item.State].color
        })
        this.steps = res.Data
      })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },

    SearchClick() {
      this.$nextTick(() => {
        this.$refs.SearchCusinfo.openForm(null, '选择开票客户')
      })
    },
    // 退票
    returnTicket(record) {
      const thisObj = this
      this.$confirm('确认退票吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        const ids = { Ids: [record.Id] }
        return new Promise((resolve, reject) => {
          thisObj.$http.post('/InvoiceManagement/Inv_ReturnTicketMain/TicketRefundAppIds', ids).then((resJson) => {
            resolve()

            if (resJson.Success) {
              thisObj.$message.success('操作成功!')

              thisObj.getDataList()
            } else {
              thisObj.$message.error(resJson.Msg)
            }
          })
        })
      })
    },
    repossess() {
      this.queryParam = { condition: 'TicketbuyerName' }
      this.changeTime(0)
      this.getDataList()
    },
    timeFormat(val) {
      // 时间格式化函数
      return moment(val).format('YYYY-MM-DD')
    },
    //发票详情-详情
    handleDetail_Detail(id) {
      this.visibleDetail_Detail = true
      this.$http
        .post('/InvoiceManagement/inv_invoicing_b/GetDataListBySingleCondition', {
          Search: { condition: 'ParentId', Keyword: id },
        })
        .then((resJson) => {
          resJson.Data.forEach((item) => {
            item.amountWithTax = this.$options.filters.NumberFormats(item.amountWithTax)
            item.taxAmount = this.$options.filters.NumberFormats(item.taxAmount)
          })
          this.invoiceDetail_detail = resJson.Data
          this.invoiceDetail_entity = {
            CreateTime: resJson.Data[0].CreateTime,
            createUserName: resJson.Data[0].createUserName,
            unit: resJson.Data[0].unit,
            Code: resJson.Data[0].Code,
          }
        })
        .catch((err) => {
          this.$message.error(err)
        })
    },
    selectIdOk() {
      this.$refs.printCopy2.openInit(
        this.dataId.filter((item) => item.Id == this.SelectIdList[0])[0].Id,
        this.dataId.filter((item) => item.Id == this.SelectIdList[0])[0].BillId,
        this.correlationId
      )
      // this.SelectIdVisible = false;
    },
    handleDelete(ids) {
      var thisObj = this
      this.$confirm('确认删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        return new Promise((resolve, reject) => {
          thisObj.$http.post('/Base_BasicData/Base_District/DeleteData', ids).then((resJson) => {
            resolve()

            if (resJson.Success) {
              thisObj.$message.success('操作成功!')

              thisObj.getDataList()
            } else {
              thisObj.$message.error(resJson.Msg)
            }
          })
        })
      })
    },

    async toGetSearchTipList(e) {
      this.searchTipResultList = []
      this.queryParam.keyword = e
      if (!this.queryParam.keyword) {
        return
      }
      await this.$http
        .post('/InvoiceManagement/Inv_InvoiceApplyMain/GetDataList', {
          PageIndex: 1,
          PageRows: 50,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: {
            ...this.queryParam,
            IsInvoice: this.queryParam.IsInvoice ? (this.queryParam.IsInvoice == 1 ? true : false) : '',
            // RefundStatus: obj[this.RefundStatus],
            StartTime: this.time[0] ? this.timeFormat(this.time[0]) : '',
            EndTime: this.time[1] ? this.timeFormat(this.time[1]) : '',
          },
          ...this.filters,
        })
        .then((resJson) => {
          if (resJson.Success && this.queryParam.keyword) {
            this.searchTipResultList = resJson.Data.map((e) => e.TicketbuyerName).slice(0, 10)
          } else {
            this.searchTipResultList = []
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
    async toGetSearchTipNameList(e) {
      this.searchTipNameList = []
      this.queryParam.RealName = e
      if (!this.queryParam.RealName) {
        return
      }
      await this.$http
        .post('/InvoiceManagement/Inv_InvoiceApplyMain/GetCreatorList', {
          id: this.queryParam.RealName,
          PageRows: 50,
          PageIndex: 1
        })
        .then((resJson) => {
          if (resJson.Success && this.queryParam.RealName) {
            this.searchTipNameList = resJson.Data.map((e) => e).slice(0, 10)
          } else {
            this.searchTipNameList = []
          }
        })
        .finally(() => {
          this.loading = false
        })
    },

    selectSearchTipFun(text) {
      this.queryParam.keyword = text
      this.searchTipResultList = []
      this.pagination.current = 1
      this.getDataList()
    },
    selectNameSearchTipFun(text) {
      this.queryParam.RealName = text
      this.searchTipNameList = []
      this.pagination.current = 1
      this.getDataList()
    },

    keywordBlurFun() {
      this.searchTipResultList = []
    },
    nameBlurFun() {
      this.searchTipNameList = []
    },
  },
  computed: {
    SelectIdRow() {
      return {
        selectedRowKeys: this.SelectIdList,
        onChange: (selectedRowKeys, selectedRows) => {
          this.SelectIdList = selectedRowKeys
        },
        getCheckboxProps: (record) => ({
          props: {
            disabled: record.name === 'Disabled User', // Column configuration not to be checked
            name: record.name,
          },
        }),
        type: 'radio',
      }
    },
  },
}
</script>
<style scoped>
.ant-steps-dot .ant-steps-item-content {
  width: 250px;
}

/deep/ .active {
  background-color: #fdf3f2 !important;
  color: #e55957;
}

/deep/ .ant-steps-item-content {
  width: 300px;
}
/deep/ .ant-card-body {
  padding-bottom: 0;
}
</style>
